package leetcode.sword;

import java.util.LinkedList;

public class Solution09 {

}

class CQueue {

    LinkedList<Integer> head, tail;
    // Stack比LinkedList要慢
    public CQueue() {
        this.head = new LinkedList<>();
        this.tail = new LinkedList<>();
    }

    public void appendTail(int value) {
        tail.push(value);
    }

    public int deleteHead() {
        //head不空
        if(!head.isEmpty()) return head.pop();
        //head空，tail空
        if(tail.isEmpty()) return -1;
        //head空，tail不空，把tail的元素全部反序调入head
        while (!tail.isEmpty()){
            head.push(tail.pop());
        }
        return head.pop();
    }
}
